Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pathifist

Package Overview
Dependencies
Maintainers
5
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pathifist

URL Path Utility

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

pathifist

travis npm

pathifist is an extremely simple, rather naïve URL path manipulation library. It is meant to be used in browser and non-browser environments to conveniently deal with URL(-ish) paths.

Installation

Using NPM:

npm install -S pathifist

Using Yarn:

yarn add pathifist

API

resolve(path, ...)

resolve is pathifist's most elaborate function: it mimics a browser's path resolution and deals with both absolute (e.g. /foo) and relative (e.g. ../) path segments. It accepts an arbitrary number of path segments as arguments.

resolve('foo', '/bar'); // => /bar
resolve('./foo', 'bar///', '../baz'); // => ./foo/baz
join(path, ...)

join glues an arbitrary number of arguments together with slashes, replacing multiple consecutive slashes in the process.

join('foo', '/bar'); // => foo/bar
join('./foo', 'bar///', '../baz'); // => ./foo/bar/../baz
dedupeSlashes(path)

dedupeSlashes removes obsolete consecutive slashes from the path it is being passed.

dedupe('//foo//bar//'); // => /foo/bar/
trimSlashes(path) / trim{Leading,Trailing}Slash(path)

trimSlashes / trim{Leading,Trailing}Slash removes single or consecutive leading and/or trailing slashes from the path it is being passed. It leaves internal slashes untouched.

trimSlashes('/foo/bar/'); // => foo/bar
trimLeadingSlash('/foo/bar/'); // => foo/bar/
trimTrailingSlash('/foo/bar/'); // => /foo/bar
ensureSlashes(path) / ensure{Leading,Trailing}Slash(path)

ensureSlashes / ensure{Leading,Trailing}Slash makes sure there are single or consecutive leading and/or trailing slash in the path it is being passed. It leaves internal slash untouched.

ensureSlashes('foo/bar'); // => /foo/bar/
ensureLeadingSlash('foo/bar'); // => /foo/bar
ensureTrailingSlash('foo/bar'); // => foo/bar/

FAQs

Package last updated on 06 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc